<template>
	<view>
		<Header title="限购" :showBack="true"></Header>
		<view v-if="info.dataTypeFlag==2" class="faceInfo">
				<view>姓&#12288;名：{{info.ownerName||'无'}}</view>
				<view>学&#12288;校：{{info.organizationName||'无'}}</view>
		</view>
		<view v-if="info.dataTypeFlag==1" class="info">
			<view class="ava">
				<!-- <open-data style="width: 100%; height: 100%;" type="userAvatarUrl"></open-data> -->
			</view>
			<view>
				<view>IC卡号：{{info.cardNo||'无'}}</view>
				<view>余&#12288;额：{{info.amount||'无'}}</view>
				<view>姓&#12288;名：{{info.ownerName||'无'}}</view>
				<view>状&#12288;态：{{info.statusFlagName||'无'}}</view>
			</view>
		</view>
		
		
		
		<view class="bg">
			
		</view>
		
		<view class="box">
			<view class="first" v-if="info.dataTypeFlag==1">
				卡号：{{cardNum}}
			</view>
			<view class="last">
				<view>限购次数:</view>
				<view>
					<radio-group @change="check" style="display: flex;justify-content: space-between;flex-wrap: wrap;">
						<label v-for="(item,index) in list" style="margin-bottom: 30upx;font-size: 26upx;width: 50%;display: flex;align-items: center;" :key="index">
							<radio style="transform: scale(0.6);" :checked="item.value==limitCount" :value="item.value" /><text>{{item.text}}</text>
						</label>
					</radio-group>
				</view>
			</view>
		</view>
		
		<button @click="summit" type="default">保存</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardNum:uni.getStorageSync('cardNo'),
				info:uni.getStorageSync('info'),
				limitCount:'',
				list:[
					{
						value:1,
						text:'每天1次'
					},
					{
						value:2,
						text:'每天2次'
					},
					{
						value:3,
						text:'每天3次'
					},
					{
						value:5,
						text:'每天5次'
					},
					
					{
						value:-1,
						text:'禁用'
					}
				]
			}
		},
		onLoad(e) {
			if(e.isLock){
				this.limitCount = -1
			}else{
				this.limitCount = this.info.limitCount
			}
		},
		methods: {
			check(e){
				this.limitCount=e.detail.value
			},
			summit(){
				let data
				if(this.info.dataTypeFlag==1){
					data = {
					 "cardNo":this.cardNum,
					 "limitCount":this.limitCount
					}
				}else if(this.info.dataTypeFlag==2){
					data = {
					 "id":this.info.id,
					 "limitCount":this.limitCount
					}
				}
				this.$http('/minprogram/api/member/setLimitCount',data,res=>{
					if(res.data.value==true){
						uni.showToast({
							icon:'none',
							title:'操作成功'
						})
						
						setTimeout(()=>{
							uni.reLaunch({
								url:'/pages/index/index?type='+this.info.dataTypeFlag
							})
						},1200)
						
					}
					
				})
			}
		}
	}
</script>

<style scoped lang="less">
.faceInfo{
		width: 100%;
		background-color: #2BAC6B;
		padding: 20upx 100upx;
		>view{
			color: #FFFFFF;
			font-size: 30upx;
			height: 80upx;
			line-height: 80upx;
		}
	}
.info{
		width: 100%;
		background-color: #2BAC6B;
		display: flex;
		padding-top: 20upx;
		.ava{
			width: 30upx;
				height: 150upx;
				border-radius: 10%;
				overflow: hidden;
				margin: 0 50upx;
				position: relative;
				top: 16upx;		
			// width: 150upx;
			// height: 150upx;
			// border-radius: 50%;
			// overflow: hidden;
			// margin:0 50upx;
			// position: relative;
			// top: 16upx;
		}
		>view:nth-child(2){
			color: #FFFFFF;
			font-size: 30upx;
			>view{
				margin-bottom: 6upx;
			}
		}
	}
	.bg{
		width: 100%;
		background-image: url(../../static/img/bg.png);
		height: 100upx;
		background-size: 100% 100%;
	}
	.box{
		background-color: #FFFFFF;
		width: 93%;
		margin: 0 auto;
		padding-bottom: 25upx;
		>view.first{
			width: 93%;
			margin: 0 auto;
			border-bottom: 1upx solid #eeeeee;
			height: 100upx;
			line-height: 100upx;
			font-size: 30upx;
			
		}
		>view.last{
			width: 93%;
			margin: 0 auto;
			border-bottom: 1upx solid #eeeeee;
			display: flex;
			padding-top: 30upx;
			>view:first-child{
				width: 30%;
				font-size: 34upx;
			}
			>view:last-child{
				width: 70%;
			}
		}
	}
	button{
		width: 93%;
		margin: 30upx auto 0;
		background-color: #2BAC6B;
		height: 80upx;
		line-height: 80upx;
		font-size: 30upx;
		color: #FFFFFF;
	}
</style>
